import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: localStorage.getItem('token'),
    userInfo: JSON.parse(sessionStorage.getItem('userInfo'))
  },
  getters: {
    getUserInfo: state => {
      return state.userInfo
    }
  },
  mutations: {
    setToken: (state, token) => {
      state.token = token
      localStorage.setItem('token', token)
    },
    setUserInfo: (state, userInfo) => {
      state.userInfo = userInfo
      sessionStorage.setItem('userInfo', JSON.stringify(userInfo))
    },
    removeInfo: (state) => {
      state.token = ''
      state.userInfo = {}
      localStorage.removeItem('token')
      sessionStorage.removeItem('userInfo')
    }
  },
  actions: {
  },
  modules: {
  }
})
